﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ALinq.BBS.DataAccess;
using System.Diagnostics;

namespace ALinq.BBS.Controllers
{
    partial class HomeController
    {
        public ActionResult DeleteTopic(int boardID, int forumID, int postListIndex,
                                        int postID, int? replyListIndex, int? replyID)
        {
            //TODO:
            using (var boards = new Boards())
            {
                var board = boards.Single(o => o.ID == boardID);
                var forum = board.Forums.Single(o => o.ID == forumID);
                if (replyID == null)
                {
                    forum.DeletePost(postID);
                    return RedirectToRoute(RouteNames.PostList, new { boardID, forumID, postListIndex });
                }
                else
                {
                    var post = forum.Posts.FindItems(o => o.ID == postID).Single();
                    post.Replies.DeleteItem(replyID.Value);
                    return RedirectToRoute(RouteNames.Post, new { boardID, forumID, postListIndex, postID, replyListIndex });
                }
            }

            return View();
        }


    }
}